package 试题和试卷;

import GUI.questionWindow;
import 数据库和网络.myDatebase;
import GUI.browzeSelectionWindow;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class selectionQuestionBaseItem extends questionBaseItem{
    public selectionQuestionBaseItem(){}

    public selectionQuestionBaseItem(int n,question currentquestion){

        super(n,currentquestion);
        detailButton.addActionListener(new detailListener());

        doButton.addActionListener(new deleteListener());

    }
    public class deleteListener implements ActionListener{
        @Override
        public void actionPerformed(ActionEvent e){
            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="delete  from questioncollection.selection_question where questionTitle='"+currentquestion.getTitle()+"'";
            try {
                questionbase.statement.execute(sql);

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            questionWindow.mainPanel.removeAll();
            questionWindow.mainPanel.updateUI();
        }

    }


    public class detailListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e){

            myDatebase questionbase=new myDatebase("questioncollection");
            String sql="select * from questioncollection.selection_question where questionTitle='"+currentquestion.getTitle()+"'";
            try {
                questionbase.statement.execute(sql);
                questionbase.resultSet=questionbase.statement.executeQuery(sql);
                while (questionbase.resultSet.next()){
                    currentquestion.setText(questionbase.resultSet.getString("questiontext"));
                    currentquestion.setDifficulty(questionbase.resultSet.getDouble("questionDifficulties"));
                    currentquestion.setFullScore(questionbase.resultSet.getInt("fullScore"));
                    currentquestion.setOption_a(questionbase.resultSet.getString("option_a"));
                    currentquestion.setOption_b(questionbase.resultSet.getString("option_b"));
                    currentquestion.setOption_c(questionbase.resultSet.getString("option_c"));
                    currentquestion.setOption_d(questionbase.resultSet.getString("option_d"));
                    currentquestion.setAnswer(questionbase.resultSet.getString("answer"));
                }

            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }

            browzeSelectionWindow selectionWindow=new browzeSelectionWindow(currentquestion);
            selectionWindow.questionContent.setText(currentquestion.getText());
            selectionWindow.title.setText(currentquestion.getTitle());
            selectionWindow.answer.setText(currentquestion.getAnswer());
            selectionWindow.difficulty.setText(""+currentquestion.getDifficulty());
            selectionWindow.score.setText(""+currentquestion.getFullScore());
            selectionWindow.aContent.setText(currentquestion.getOption_a());
            selectionWindow.bContent.setText(currentquestion.getOption_b());
            selectionWindow.cContent.setText(currentquestion.getOption_c());
            selectionWindow.dContent.setText(currentquestion.getOption_d());
            selectionWindow.mainPanel.updateUI();


        }
    }
}
